<?php
/**
 * File: Util.php:YCMS
 * User: xiaoyan f@yanyunfeng.com
 * Date: 15-5-14
 * Time: 下午4:55
 * @Description
 */
function getFieldTypeName($type){
    return FieldType::getText($type);
}

function dataState($state){
    return DataState::getText($state);
}
function noticeState($state){
    return NoticeState::getText($state);
}
function taskState($state){
    return TaskState::getText($state);
}
function getAuthLib(){
    if(!class_exists('Auth')){
        include LIB_DIR.'/libs/Auth.php';
    }

    if(Cache::getInstance()->exists('authLib')){
        return Cache::getInstance()->get('authLib');
    }
    $lib = new Auth();
    Cache::getInstance()->set('authLib',$lib);
    return $lib;
}

/**
 * 获取登录用户的UID
 * @return int
 */
function getLoginUid(){
    if(isset($_SESSION[OSW_UID])) return $_SESSION[OSW_UID];
    return 0;
}
function permission($name){
    $uid = getLoginUid();
    if($uid < 1) return ' hidden ';
    $hasPermission = getAuthLib()->check($name,$uid,RuleType::BUTTON);
    if($hasPermission == false){
        return ' hidden ';
    }
    return '';
}
function hasPermission($name){
    return permission($name) == '';
}